ARG ELIXIR="1.14.2"
ARG ERLANG="25.1.2"
ARG ALPINE="3.16.2"

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR}-erlang-${ERLANG}-alpine-${ALPINE}"
ARG RUNNER_IMAGE="alpine:${ALPINE}"

FROM ${BUILDER_IMAGE} AS builder

ARG MIX_ENV="prod"

RUN mix local.hex --force && \
    mix local.rebar --force

COPY mix.exs mix.lock ./
RUN mix deps.get --force --only prod

COPY config ./config

RUN mix deps.compile

COPY lib ./lib

RUN mix release --force --path /export

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}

RUN apk add --no-cache libstdc++ openssl ncurses-libs

COPY --from=builder /export /opt

EXPOSE 8080

ENTRYPOINT ["/opt/bin/framework_benchmarks"]
CMD ["start"]
